# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Cookie Engineer <cookiengineer@protonmail.ch>

pkgname=('dark-reader' 'firefox-dark-reader' 'thunderbird-dark-reader')
pkgbase=dark-reader
_name=${pkgbase/-}
pkgver=4.9.70
pkgrel=1
pkgdesc='Inverts brightness of web pages and aims to reduce eyestrain while browsing the web'
arch=('any')
url=https://darkreader.org/
license=('MIT')
makedepends=('git' 'npm')
source=("git+https://github.com/$_name/$_name.git#tag=v$pkgver")
b2sums=('SKIP')

prepare() {
  cd "$_name"
  npm ci
}

build() {
  cd "$_name"
  npm run build
}

check() {
  cd "$_name"
  npm test
}

package_dark-reader() {
  pkgdesc+=' (unpacked webextension)'
  cd "$_name"/build/release/chrome
  install -d "$pkgdir"/usr/lib/$pkgbase
  cp -r -- * "$pkgdir"/usr/lib/$pkgbase
}

package_firefox-dark-reader() {
  groups=('firefox-addons')
  cd "$_name"/build/release
  install -Dm644 "$_name"-firefox.xpi \
    "$pkgdir"/usr/lib/firefox/browser/extensions/addon@"$_name".org.xpi
}

package_thunderbird-dark-reader() {
  cd "$_name"/build/release
  install -Dm644 "$_name"-thunderbird.xpi \
    "$pkgdir"/usr/lib/thunderbird/extensions/addon@"$_name".org.xpi
}
